import {mRequest} from '@/utils/request'
import ECharts from 'vue-echarts'
import 'echarts'

export default {
  components: {
    'v-chart': ECharts
  },
  data() {
    return {
      option: {},
      mRequest: mRequest
    }
  },
  methods: {
    init(property) {
      this.requestData(property)
    },
    oneLineOption(obj){
      return {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'line'
          }
        },
        xAxis: {
          type: 'category',
          data: this.R.propOr([], 'xAxis', obj)
        },
        yAxis: {
          type: 'value'
        },
        legend: {
          bottom: 10,
          data: [this.userName]
        },
        series: [
          {
            name: this.userName,
            data: this.R.propOr([], 'data', obj),
            type: 'line',
            smooth: true
          }
        ]
      }
    },
    normalLineOption(obj) {
      const xData = this.R.propOr([], 'data', obj)

      return {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'line'
          }
        },
        xAxis: {
          type: 'category',
          data: this.R.propOr([], 'xAxis', obj)
        },
        yAxis: {
          type: 'value'
        },
        legend: {
          type: 'scroll',
          bottom: 10,
          data: this.R.map((item) => item.name, xData)
        },
        series: this.R.map((item) => ({
          name: item.name,
          data: item.data,
          type: 'line',
          smooth: true
        }), xData)
      }
    },
    normalRadarOption(obj){
      return {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          type: 'scroll',
          bottom: 10,
          data: this.R.propOr([], 'legendDate', obj)
        },
        radar: {
          indicator: this.R.propOr([], 'indicator', obj)
        },
        series: [{
          type: 'radar',
          data: this.R.propOr([], 'data', obj)
        }]
      }
    },
    normalPieOption(obj) {
      return {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          type: 'scroll',
          bottom: 10,
          data: this.R.propOr([], 'legendData', obj)
        },
        series: [
          {
            name: '辅料类型',
            type: 'pie',
            data: this.R.propOr([], 'data', obj)
          }
        ]
      }
    }
  }
}
